package lk.icta.user.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Duminda Dharmakeerthi
 */
public class HashUtil {

    private static final Logger logger = LoggerFactory.getLogger(HashUtil.class);

    public static String hashString(String s) {
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            logger.warn("Cannot instantiate a SHA-1 message digest", e);
            throw new RuntimeException("Cannot instantiate a SHA-1 message digest", e);
        }
        sha.reset();
        sha.update(s.getBytes());
        return new String(Base64.encode(sha.digest()));
    }
}
